$(function() {
	var timeHour = '',
		timeMinute = '';
	for (var i = 0; i < 24; i++) {
		if (i < 10) {
			timeHour += '<p>0' + i + '</p>';
		} else {
			timeHour += '<p>' + i + '</p>';
		}
	}
	for (var i = 1; i <=8; i++) {
		
			timeMinute += '<p>' + i + '</p>';
		
	}
	timeMinute += '<p>卡' + 1 + '</p>';
	timeMinute += '<p>卡' + 2 + '</p>';
	timeMinute += '<p>卡' + 3 + '</p>';
	//$('.time-hour').empty().append(timeHour);
	$('.time-minute').empty().append(timeMinute);
	$('.time-hour,.time-minute').find('p:first').addClass('time-current');
	$('.time-hour,.time-minute').css({
		'-webkit-transform': 'translateY(30px)',
		'-moz-transform': 'translateY(30px)',
		'transform': 'translateY(30px)'
	});
	var n1 = 0,
		n2 = 0,
		b1 = false,
		b2 = false,
		startPot1 = {
			x: 0,
			y: 0
		},
		endPot1 = {
			x: 0,
			y: 0
		},
		startPot2 = {
			x: 0,
			y: 0
		},
		endPot2 = {
			x: 0,
			y: 0
		};
	/* time-hour */
	$("#time-hour")[0].addEventListener("touchstart", function(e) {
		e.preventDefault();
		$.extend(startPot1, {
			x: e.touches[0].pageX,
			y: e.touches[0].pageY
		});
	}, false);
	$("#time-hour")[0].addEventListener("touchmove", function(e) {
		e.preventDefault();
		b1 = true;
		$.extend(endPot1, {
			x: e.touches[0].pageX,
			y: e.touches[0].pageY
		});
		$('.time-hour').css({
			'-webkit-transform': 'translateY(' + ((n1 + 1) * 30 + (endPot1.y - startPot1.y)) + 'px)',
			'-moz-transform': 'translateY(' + ((n1 + 1) * 30 + (endPot1.y - startPot1.y)) + 'px)',
			'transform': 'translateY(' + ((n1 + 1) * 30 + (endPot1.y - startPot1.y)) + 'px)',
		});
	}, false);
	$("#time-hour")[0].addEventListener("touchend", function(e) {
		e.preventDefault();
		if (b1) {
			b1 = false;
			n1 += Math.round((endPot1.y - startPot1.y) / 30);
			if (n1 < -23) {
				n1 = -23;
			} else if (n1 > 0) {
				n1 = 0
			}
			$('.time-hour').css({
				'-webkit-transform': 'translateY(' + ((n1 + 1) * 30) + 'px)',
				'-moz-transform': 'translateY(' + ((n1 + 1) * 30) + 'px)',
				'transform': 'translateY(' + ((n1 + 1) * 30) + 'px)',
			});
			$('.time-hour').find('p').eq(-n1).addClass('time-current').siblings().removeClass('time-current');
			if (!$('.time-hour').find('p:first').hasClass('time-current') && !$('.time-minute').find('p:first').hasClass('time-current')) {
				$('.time-symbol').find('p:first').css({
					'visibility': 'visible'
				});
			} else {
				$('.time-symbol').find('p:first').css({
					'visibility': 'hidden'
				});
			}
		}
	}, false);
	/* time-minute */
	$("#time-minute")[0].addEventListener("touchstart", function(e) {
		e.preventDefault();
		$.extend(startPot2, {
			x: e.touches[0].pageX,
			y: e.touches[0].pageY
		});
	}, false);
	$("#time-minute")[0].addEventListener("touchmove", function(e) {
		e.preventDefault();
		b2 = true;
		$.extend(endPot2, {
			x: e.touches[0].pageX,
			y: e.touches[0].pageY
		});
		$('.time-minute').css({
			'-webkit-transform': 'translateY(' + ((n2 + 1) * 30 + (endPot2.y - startPot2.y)) + 'px)',
			'-moz-transform': 'translateY(' + ((n2 + 1) * 30 + (endPot2.y - startPot2.y)) + 'px)',
			'transform': 'translateY(' + ((n2 + 1) * 30 + (endPot2.y - startPot2.y)) + 'px)',
		});
	}, false);
	$("#time-minute")[0].addEventListener("touchend", function(e) {
		e.preventDefault();
		if (b2) {
			b2 = false;
			n2 += Math.round((endPot2.y - startPot2.y) / 30);
			if (n2 < -10) {
				n2 = -10;
			} else if (n2 > 0) {
				n2 = 0
			}
			$('.time-minute').css({
				'-webkit-transform': 'translateY(' + ((n2 + 1) * 30) + 'px)',
				'-moz-transform': 'translateY(' + ((n2 + 1) * 30) + 'px)',
				'transform': 'translateY(' + ((n2 + 1) * 30) + 'px)',
			});
			$('.time-minute').find('p').eq(-n2).addClass('time-current').siblings().removeClass('time-current');
			if (!$('.time-hour').find('p:first').hasClass('time-current') && !$('.time-minute').find('p:first').hasClass('time-current')) {
				$('.time-symbol').find('p:first').css({
					'visibility': 'visible'
				});
			} else {
				$('.time-symbol').find('p:first').css({
					'visibility': 'hidden'
				});
			}
		}
	}, false);
});